import { ref } from 'vue';
import { defineStore } from 'pinia';

export const usearticleListStore = defineStore('articleList', () => {
  const imgList = ref([
    '黑板-左森健-2022-long.png',
    '马路-路遥-299-short.png',
    '家居室内-Ace-2011-long.png',
    '城市-枫-182-long.png',
    '咖啡生活-夜-2-short.png',
    '舒适-菲尼斯-2981-short.png'
  ]);
  function roundRobinSplit(arr) {
    return [arr.filter((_, i) => i % 2 === 0), arr.filter((_, i) => i % 2 !== 0)];
  }
  function parseFilename(filename) {
    // 最后一个点号的位置
    const lastDotIndex = filename.lastIndexOf('.');
    const name = filename.slice(0, lastDotIndex); // "马路-路遥-299-short.test"
    const ext = filename.slice(lastDotIndex + 1); // "png"
    const segments = name.split('-');
    return {
      title: segments[0], // "马路"
      author: segments[1], // "路遥"
      downloadTime: segments[2], // "299"
      type: segments[3], // "short.test"
      extension: ext, // "png"
      imgUrl: '../../static/images/' + filename
    };
  }
  return { imgList, roundRobinSplit, parseFilename };
});
